<template>
	<div class="sys-dictType-container">
		<el-dialog v-model="state.isShowDialog" draggable :close-on-click-modal="false" width="700px">
			<template #header>
				<div style="color: #fff">
					<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit />
					</el-icon>
					<span> {{ props.title }} </span>
				</div>
			</template>
			<el-form :model="state.ruleForm" ref="ruleFormRef" label-width="auto">
				<el-form-item label="序号" prop="serialNumber"
					:rules="{ required: true, message: '序号非空', trigger: 'change' }">
					<el-input v-model="state.ruleForm.serialNumber"></el-input>
				</el-form-item>
				<el-form-item label="领料单号" prop="pickingNumber"
					:rules="{ required: false, message: '领料单号非必填自己可生成', trigger: 'change' }">
					<el-input v-model="state.ruleForm.pickingNumber" placeholder="领料单号非必填自己可生成" clearable></el-input>
				</el-form-item>
				<el-form-item label="托盘" prop="tray" :rules="{ required: true, message: '托盘不为空', trigger: 'change' }">
					<el-input v-model="state.ruleForm.tray"></el-input>
				</el-form-item>

				<!-- 设备位置 -->
				<el-form-item label="出入口" prop="entranceandExit"
					:rules="{ required: true, message: '托盘不为空', trigger: 'change' }">
					<el-input v-model="state.ruleForm.entranceandExit"></el-input>
				</el-form-item>
				<!-- <el-form-item :label="$slots['提升机_label'] || '提升机出/入口'" prop="inOrOut">
					
					<el-input v-model="state.ruleForm.deviceId"></el-input>
				</el-form-item> -->

			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="cancel">取 消</el-button>
					<el-button type="primary" @click="submit">确 定</el-button>
				</span>
			</template>

		</el-dialog>
	</div>
</template>

<script lang="ts" setup name="Edidevice">


import { getAPI } from '/@/utils/axios-utils';
import { AccountTypeEnum, UpdateDictTypeInput } from '/@/api-services/models';
import { useUserInfo } from '/@/stores/userInfo';
import { ref, onMounted, reactive } from 'vue';

import { GetMateriaiPageListApi, InseertMateriaiApi, UpdateMateriaiApi, DownloadMateriaiApi, MateriaiinportApi, MateriaiexportApi } from '/@/api-services/apis/warehosue-materiai-api'; // 导入 API 服务
import { MateriailIssuanceInput } from '/@/api-services/models/warehous-materiai-input'; // 导入获取实体
import { Message } from '@element-plus/icons-vue/dist/types';
import { update } from 'lodash-es';
import { clone } from 'sortablejs';
import { fa } from 'element-plus/es/locale';

// 打开弹窗
const openDialog = (row: any) => {
	state.ruleForm = JSON.parse(JSON.stringify(row));
	state.isShowDialog = true;
	console.log(state.ruleForm);
	ruleFormRef.value?.resetFields();

};


const props = defineProps({
	title: String,
});
const emits = defineEmits(['handleQuery']);
const ruleFormRef = ref();
const state = reactive({
	loading: false,
	isShowDialog: false,
	ruleForm: {} as MateriailIssuanceInput,


});
// 在 onMounted 生命周期钩子中获取仓库数据

// 关闭弹窗
const closeDialog = () => {
	emits('handleQuery');
	state.isShowDialog = false;
};

// 取消
const cancel = () => {
	state.isShowDialog = false;
};

// 提交
const submit = () => {
	ruleFormRef.value.validate(async (valid: boolean) => {
		if (!valid) return;
		//state.ruleForm.id != undefined && state.ruleForm.id > 0
		if (props.title && props.title.includes("编辑")) {

			console.log(state.ruleForm);
			await UpdateMateriaiApi(state.ruleForm);

		} else {

			await InseertMateriaiApi(state.ruleForm);
		}
		closeDialog();
	});
};

// 导出对象
defineExpose({ openDialog });
</script>
